在 Mac 裝置上運行 React Android project,出現以下錯誤。
> npx expo run:android
› Building app...
Configuration on demand is an incubating feature.
> Configure project :expo
Using expo modules
- expo-application (5.9.1)
- expo-asset (10.0.10)
- expo-constants (16.0.2)
- expo-device (6.0.2)
- expo-file-system (17.0.1)
- expo-font (12.0.10)
- expo-keep-awake (13.0.2)
- expo-modules-core (1.12.24)
- expo-notifications (0.28.16)
BUILD SUCCESSFUL in 4s
255 actionable tasks: 18 executed, 237 up-to-date
Starting Metro Bundler
(QR code)
› Metro waiting on
com.jim.notification://expo-development-client/?url=http%3A%2F%2F192.168.1.110%3A8081
› Scan the QR code above to open the project in a development build. Learn more
› Using development build
› Press s │ switch to Expo Go
› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web
› Press j │ open debugger
› Press r │ reload app
› Press m │ toggle menu
› Press o │ open project code in your editor
› Press ? │ show all commands
› Opening on Android...
CommandError: No development build (com.jim.notification) for this project is installed. Please make and install a development build on the device first.
Learn more
› Opening com.jim.notification://expo-development-client/?url=http%3A%2F%2F192.168.1.110%3A8081 on Pixel_6
› Logs for your project will appear below. Press Ctrl+C to exit.
Android Bundled 505ms node_modules/expo/AppEntry.js (711 modules)
在應用程式的主頁面,想取得 Expo push token 時,出現以下訊息:
Error: Call to function ExpoPushTokenManager.getDevicePushTokenAsync has been rejected
Caused by: java.lang.lllegalStateException: Default FirebaseApp is not initialized in thes process com.jim.notification. Make sure to call FirebaseApp.initializeApp(context) first.
使用 npx expo prebuild --platform android --clean
來進行預備構建。
> npx expo prebuild --platform android --clean
Warning! Your git working tree is dirty.
It's recommended to commit all your changes before proceeding, so you can revert the changes made by this command if necessary.
✔ Would you like to proceed? … yes
✔ Cleared android code
✔ Created native directory
✔ Updated package.json | no changes
» android: userInterfaceStyle: Install expo-system-ui in your project to enable this feature.
✔ Finished prebuild
重新執行 npx expo run:android
,在 Expo push token 有相同的異常訊息。
原來,雖然我們引進了 React Expo Notification library,Android 裝置上的推播邏輯仍需在 Android 原生平台依賴 Google FCM 來實現。